﻿var currentPage = 0;
var numPerPage = 9;
var totalPage = 0;
$(document).ready(function() {
  $("ul#mainmenu li input").click(gotourl);
  totalPage = Math.ceil($('ul#mainmenu li').length/numPerPage );
  $("div#page").html(pagecontent);
  $('ul#mainmenu').each(changeLine);
});
$(document).keydown(function(event){
if(event.keyCode>48&&event.keyCode<58){
   var menuindex = event.keyCode-48;

  var a = currentPage*numPerPage+menuindex-1;
  var $a=$("ul#mainmenu li:eq("+a+") input");
  $a.trigger('click');
}else if(event.keyCode>96&&event.keyCode<106){
    menuindex = event.keyCode-96;

   a = currentPage*numPerPage+menuindex-1;
  $a=$("ul#mainmenu li:eq("+a+") input"); 
  $a.trigger('click');
}else if(37==event.keyCode||38==event.keyCode){  
  currentPage --;
  if(currentPage <0)
    currentPage =totalPage-1;  
  
   $("div#page").html(pagecontent);
   $('ul#mainmenu').each(changeLine);
}else if(39==event.keyCode||40==event.keyCode){
  
  currentPage++;
  if(currentPage>=totalPage)
  currentPage=0;  
  $("div#page").html(pagecontent);
  $('ul#mainmenu').each(changeLine);
}
});
var pagecontent = function(){
  var html='';
  for(var i=0;i<totalPage;i++){
    if(i == currentPage)
        html+='<span class="heighlight">O</span> ';
    else
        html+="o ";    
  }
  return html;
}
var changeLine = function(){   
    var $table = $(this);    
    $table.find('li').show();
    var  startLine=(currentPage) * numPerPage;
    var  endLine=(currentPage+1) * numPerPage -1;
     $table.find('li:lt('+startLine+')').hide();
       $table.find('li:gt('+endLine+')').hide();
  };
  var gotourl = function(){
    var $a = $(this);  
    window.location =$a.attr('title')
  }
  